const app = getApp();
const requestUtil = require("../../../utils/request");
const api = require("../../../config/api");
const common = require("../../../utils/common");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ToolTabCur: 0,
        TabCur: 0,
        toolbars:[
            {name:"写汇报", class:"cuIcon-post", url: "/pages/question/center/center"},
            {name:"看汇报", class:"cuIcon-punch", url: "/pages/question/list/answerList"},
            {name:"统计", class:"cuIcon-crown", url: "/pages/question/total/questionTotal"},
            {name:"我的", class:"cuIcon-profile", url: "/pages/question/my/myQuestionList"},
        ],
        tabs: ['汇报问卷'], //,'调研问卷'
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let user = app.globalData.employeeInfo;
        this.setData({
            user: user
        });
        this.questionList();
    },
    async questionList(){
        let that = this;
        let res = await requestUtil.request("POST", api.urls.questionList, {
            companyId: that.data.user.companyId,
            userIds: that.data.user.isAdmin == 0 ? that.data.user.id : null,
        })
        let qyList1 = [], qyList2 = [];
        for(var i in res.data.data) {
            if("1" == res.data.data[i].questionType) {
                res.data.data[i].questionContent = JSON.parse(res.data.data[i].questionContent);
                qyList1.push(res.data.data[i])
            }else if("2" == res.data.data[i].questionType) {
                res.data.data[i].questionContent = JSON.parse(res.data.data[i].questionContent);
                    qyList2.push(res.data.data[i])
            }
        }
        that.setData({
            qyList1: qyList1,
            qyList2: qyList2
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    toolTabSelect(e){
        let index = e.currentTarget.dataset.index;
        wx:wx.navigateTo({
          url: this.data.toolbars[index].url
        })
    },
    tabSelect(e) {
        this.setData({
          TabCur: e.currentTarget.dataset.id,
          scrollLeft: (e.currentTarget.dataset.id-1)*60
        })
    },
    toWorkpage(e) {
        let id = e.currentTarget.dataset.id;
        wx:wx.navigateTo({
          url: '/pages/question/questionDetail/questionDetail?questionId=' + id,
        })
    }
})